package com.xiaotu.factory.simplefactory.pizzastore.order;

import com.xiaotu.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.xiaotu.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.xiaotu.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.xiaotu.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * @author 张晓
 * @create 2020-06-19 11:29
 */
//简单工厂类
public class SimpleFactory {
    //根据orderType 返回对应的 Pizza对象
    public Pizza createPizza(String orderType){
        Pizza pizza = null;
        System.out.println("使用简单工厂模式");
        if (orderType.equals("greek")) {
            pizza = new GreekPizza("希腊披萨");
        }else if (orderType.equals("cheese")){
            pizza = new CheesePizza("奶酪披萨");
        }else if(orderType.equals("pepper")){
            pizza = new PepperPizza("胡椒披萨");
        }
        return pizza;
    }

    //简单工厂模式，也叫静态工厂模式
    public static Pizza createPizza2(String orderType){
        Pizza pizza = null;
        System.out.println("使用简单工厂模式2");
        if (orderType.equals("greek")) {
            pizza = new GreekPizza("希腊披萨");
        }else if (orderType.equals("cheese")){
            pizza = new CheesePizza("奶酪披萨");
        }else if(orderType.equals("pepper")){
            pizza = new PepperPizza("胡椒披萨");
        }
        return pizza;
    }
}
